package com.itheima.leetcode.od.c.logicalsimulation;

import java.util.Scanner;

/**
 * <h3>高效货运来自异国的客人/幸运数字</h3>
 */
public class EfficientFreight {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int k, n, m;
        try {
            String input_str = in.nextLine();
            String[] tmp2 = input_str.split(" ");
            int[] nums = new int[tmp2.length];
            for (int i = 0; i < tmp2.length; i++) {
                nums[i] = Integer.parseInt(tmp2[i]);
            }
            k = nums[0];
            n = nums[1];
            m = nums[2];
            if (k <= 0 || n <= 0 || m <= 1 || n >= m) {
                System.out.println(0);
                return;
            }
        } catch (Exception e) {
            System.out.println(0);
            return;
        }

        int result = 0;
        while (k > 0) { // 进制转换 余数倒序组成最后的结果
            if (k % m == n) {
                result += 1;
                k /= m;
            } else {
                k /= m;
            }
        }
        System.out.println(result);
    }
}